<?php get_header() ?>

<h5>Articles commentés récemment</h5>
            <?php
            $number=1000;
            $authorid = $curauth->ID;
            $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' and user_id='$authorid' ORDER BY comment_date_gmt DESC LIMIT $number");
            ?>
            <p>L'utilisateur à poster des commentaires dans les articles suivants :</p>
            <div id="lastcom"><ul><li>
			<?php
                if ( $comments ) : foreach ( $comments as $comment) :
                echo  '<li><a href="'. get_comment_link($comment->comment_ID) . '">' . get_the_title($comment->comment_post_ID) . '</a></li>';
                endforeach;
                else:
             ?>
            <?php echo '<p>Il n\'y a actuellement aucun commentaire.'; ?>
            <?php endif; ?>
           </li></ul></div>




<div class="les_articles">
            <?php
            $blog_category = get_option(THEME_NAME.'_blog_include_category');
            $categories = get_categories('orderby=name');
            $include_category = null;
            $slug = get_page_link();

            foreach ($categories as $category_list) {
                if(!empty($blog_category[0][$category_list->cat_ID])) {
                    $cat = 	$category_list->cat_ID.",";
                    $include_category = $include_category.$cat;
                }
            }

            $value = get_option(THEME_NAME.'_blog_number_of_posts');
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 0;
            $args=array('cat'=>$include_category, 'post_status' => 'publish','paged' => $paged,'posts_per_page' => get_option('posts_per_page'),'ignore_sticky_posts'=> 1);

            //La requête
            query_posts($args);
            $i=1;

            //La boucle
            if ( have_posts() ) : while ( have_posts() ) : the_post();
                    $data = get_post_meta( $post->ID, GD_THEME, true );
                    $title = the_title('','',FALSE);
                    $title = strtoupper($title);
                    if ($title<>substr($title,0,165)) {
                        $dots = "...";
                    }else {
                        $dots = "";
                    }
                    ?>

            <div class="blog-one-post">
                        <?php $imagedata = simplexml_load_string(get_the_post_thumbnail()); ?>
                        <?php
                        $comments = get_comments("post_id=$post->ID");
                        $num_of_comments = 0;
                        foreach($categories as $category){
                        if($category->cat_ID == $id){
                        $cat_slug = $category->slug;
                        }
                        }
                        foreach($comments as $comm) :
                            $num_of_comments++;
                        endforeach;
                        $written = $post->post_author;
                        $user = get_user_by('id',$written);
                        $written = $user->nickname;
                        ?>

                <div class="titre_article"><a href="<?php the_permalink(); ?>"><?php echo substr($title,0,165).$dots; ?></a></div>

                        <?php if (has_post_thumbnail()) { ?>
                <div class="cadre_image">
                            <a href="<?php the_permalink();?>"><?php the_post_thumbnail(); ?></a>
                </div>
                            <?php }?>

                <div class="infos_article">
                    <div class="infos-text">Auteur : <?php the_author_posts_link(); ?></div>
                    <div class="infos-text">Date de publication : <?php the_time('d');?><?php the_time('F');?> <?php the_time('Y');?></div>
                    <div class="infos-text">Commentaire(s) :<?php echo $num_of_comments; ?></div>
                </div>

                <div class="appercu_article">
                    <div class="preview"><?php truncate_post(600);?></div>
                    <a class="lire_plus" href="<?php the_permalink(); ?>">Lire</a>
                </div>
            </div>

                <?php endwhile;	?>
    <?php wp_paginate() //pour ajouter la fonction de navigation par pages?>
            <?php else: ?>
            <?php endif; ?>

        </div>

 <?php get_sidebar() ?>



<?php get_footer() ?>
